package com.tywj.panda.user.api

import androidx.collection.ArrayMap
import com.tywj.lib.net.retrofit.request.GetRequest
import com.tywj.lib.net.retrofit.request.PostRequest
import com.tywj.panda.customer.common.api.CommonApi
import com.tywj.panda.customer.common.manager.AuthorityManager
import com.tywj.panda.customer.common.tool.HttpTool

/**
 * @desc 用户组件网络请求接口
 * @author June Yang
 * @date 2019/12/12
 */
object UserApi {

    // GET /ticket/orderinfo/search/order
    //订单分页查询
    private var USER_ORDER_LIST = CommonApi.API_TICKET_URL + "ticket/orderinfo/search/order"

    private var USER_DETAILS = "user/user-detail"

    private var ORDER_DETAIL = CommonApi.API_TICKET_URL + "ticket/orderinfo/search/order/detail/"

    //修改用户详情
    private var USER_CENTER_DETAILS = CommonApi.API_USER_URL + "user/info/update/userDetail"

    fun listPriceOrder(): GetRequest = HttpTool.get(USER_ORDER_LIST)

    //在分页中传递的参数中，不同的参数放在这里操作 相同的下层到底层中去
    /**
     * @param orderStatus 订单状态 0 待付款 1付款 2已退款 3已取消 4已过期 5支付失败 6锁定（预留）7 已完成（预留） 99未知（预留）
     */
    fun listBillingOrderParams(orderStatus: String, time: Long = 0L): ArrayMap<String, String> {
        val map = ArrayMap<String, String>()
        map["order_status"] = orderStatus
        map["uid"] = AuthorityManager.uid
        map["page_size"] = "10" //分页大小
        map["page_type"] = "1" ////1:当前时间之前(下一页) 2:当前时间之后（上一页)
        if (time == 0L) {
            map["create_date"] = System.currentTimeMillis().toString()
        } else {
            map["create_date"] = time.toString()
        }
        return map
    }


    fun getOrderDetail(orderId: String): GetRequest {
        return HttpTool.get(ORDER_DETAIL).param("order_serial_no", orderId)
    }

    fun getUserDetails(uid: String): PostRequest {
        return HttpTool.post(USER_DETAILS).param("uid", uid)
    }

    fun saveUserInfo(avatar: String = "", nickName: String = ""): PostRequest {

        val post = HttpTool.post(USER_CENTER_DETAILS).param("uid", AuthorityManager.uid)

        if (avatar.isNotEmpty()) {
            post.param("avatar", avatar)
        }
        if (nickName.isNotEmpty()) {
            post.param("nick_name", nickName)
        }
        return post

    }
}